package com.cuz.for2024;

public class T38 {

    public static void main(String[] args) {
        System.out.println(new T38().countAndSay(4));
    }
    public String countAndSay(int n) {
        if (n == 1) {
            return "1";
        }
        if (n == 2) {
            return "11";
        }
        String pre = countAndSay(n - 1);
        char[] preCharArray = pre.toCharArray();
        char preChar = preCharArray[0];
        int count = 1;

        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < preCharArray.length; i++) {
            char now = preCharArray[i];
            if (now == preChar) {
                count++;
            } else {
                sb.append(count);
                sb.append(preChar);
                preChar = now;
                count = 1;
            }
        }
        sb.append(count);
        sb.append(preChar);
        return sb.toString();
    }

}
